#!/bin/sh
#
# repro SIP proxy server
#
# chkconfig:   2345 70 30
# description: SIP proxy server routes SIP messages between endpoints

### BEGIN INIT INFO
# Provides: reTurnServer
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 3 5
# Default-Stop: 0 1 2 4
# Short-Description: SIP proxy server
# Description: SIP proxy server routes SIP messages between endpoints
### END INIT INFO

base=${0##*/}
link=${base#*[SK][0-9][0-9]}

# Source function library.
. /etc/rc.status
rc_reset

exec="/usr/sbin/reTurnServer"
prog="reTurnServer"
config="/etc/reTurn/reTurnServer.config"
proguser=return
proggrp=return

lockfile=/var/lock/subsys/$prog
piddir=/var/run/$prog
pidfile=${piddir}/${prog}.pid

test -x $exec || exit 5
test -f $config || exit 6
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog


case "$1" in
    start)
        [ -d $piddir ] || mkdir -p $piddir && chown ${proguser}:${proggrp} $piddir
        echo "Starting $prog "
        startproc -p $pidfile $exec $config
        rc_status -v
        ;;
    stop)
        echo -n "Stopping $prog "
        killproc $exec
        rc_status -v
        ;;
    restart)
        $0 stop
        $0 start
        rc_status
        ;;
    reload)
        echo -n "Reload service $prog "
        rc_failed 3
        rc_status -v
        ;;
    force-reload)
        echo -n "Reload service $prog "
        $0 try-restart
        rc_status
        ;;
    status)
        echo -n "Checking for service $prog "
        /sbin/checkproc $exec
        rc_status -v
        ;;
    probe)
        test $config -nt $pidfile && echo reload
	;;
    condrestart|try-restart)
        if test "$1" = "condrestart"; then
              echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
        fi
        $0 status
        if test $? = 0; then
              $0 restart
        else
              rc_reset
        fi
        rc_status
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|probe}"
        exit 2
esac
rc_exit

